package com.huadao.cart_ccs.base;

import android.content.Context;

import com.huadao.cart_ccs.data.source.http.BaseImpl;

import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;

public class BaseHttpPresenter<T extends BaseView> extends BasePresenter<T> implements BaseImpl {
    private CompositeDisposable mCompositeDisposable;

    @Override
    public void attachView(T baseView) {
        super.attachView(baseView);
        if (null == mCompositeDisposable) {
            mCompositeDisposable = new CompositeDisposable();
        }
    }

    @Override
    public void detachView() {
        if (null != mCompositeDisposable) {
            mCompositeDisposable.clear();
        }
        super.detachView();
    }

    @Override
    public boolean addDisposable(Disposable disposable) {
        if (null != mCompositeDisposable) {
            mCompositeDisposable.add(disposable);
        }
        return true;
    }

    @Override
    public Context getContext() {
        if(!isViewAttached()){
            return null;
        }
        return baseView.getContext();
    }

}
